#include<iostream>
using namespace std;
const int N = 1e5 + 10;
int father[N];
int n, m;
int size1[N];
int find(int x)
{
	if (x != father[x]) {
		father[x] = find(father[x]);
	}
	return father[x];
}
int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		father[i] = i;
		size1[i] = 1;
	}
	while (m--) {
		char op[5];
		cin >> op;
		int a, b;
		if (op[0] == 'C') {
			cin >> a >> b;
			if (find(a) == find(b)) {
				continue;	
			}
			size1[find(b)] += size1[find(a)];
			father[find(a)] = find(b);
		}
		else if (op[1] == '1') {
			cin >> a >> b;
			if (find(a) == find(b)) {
				cout << "Yes" << endl;
			}
			else {
				cout << "No" << endl;
			}
		}
		else {
			int a;
			cin >> a;
			cout << size1[find(a)] << endl;
		}
	}
	return 0;
}